/*
 * dmalloc_test.c
 *
 *  Created on: 2009-1-5
 *      Author: doug
 */

#include <stdio.h>
#include <stdlib.h>
#ifdef USE_DMALLOC
#include <dmalloc.h>
#endif

// This is a GCCE toolchain workaround needed when compiling with GCCE
// and using main() entry point
#ifdef __GCCE__
#include <staticlibinit_gcce.h>
#endif

int main()
{
  char *test[5];
  unsigned int i;
//  setenv("DMALLOC_OPTIONS", "log=logfilename,debug=0x8400000", 0);
  setenv("DMALLOC_OPTIONS", "log-trans,log-stats,log=c:\\data\\dmalloc_tr_openc.log", 0);

  for (i=0; i < 5; i++)
  {
    unsigned int size = rand()%1024;
    test[i] = (char *)malloc(size);
    printf ("Allocated memory of size %d\n",size);
  }
  for (i=0; i<2; i++)
    free(test[i*2]);

  for (i=0; i<5; ++i)
	  {
		unsigned int size = rand()%1024;
		test[i] = new char[size];
		printf ("Allocated memory of size %d using new operator\n",size);
	  }
  for (i=0; i<2; i++)
    delete [] (test[i*2]);

  return getchar();
}
